﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.MT3DMS.DomainLayer
{
    [Serializable]
    public class MixingItem:ICloneable
    {

        public MixingItem(int row,int col ,int layer,MixingSSType type,int nPeriod,List<string> speciesList)
        {

            this._row = row;

            this._col = col;

            this._layer = layer;

            this._ssType = type;



            this._spDic = new Dictionary<string, List<double>>();


            foreach (string sp in speciesList)
            {
                List<double> value=new List<double> ();
                for (int i = 0; i < nPeriod; i++)
			{
                    value.Add (0);
			 
			}

                this._spDic.Add(sp,value);
                
            }


            this._nPeriods = nPeriod;
            
      



 
        }

        /// <summary>
        /// 此方法用于MT3D映射用
        /// </summary>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <param name="layer"></param>
        /// <param name="type"></param>
        /// <param name="nPeriod"></param>
        /// <param name="speciesList"></param>
        /// <param name="speciesValue"></param>
        public MixingItem(int row, int col, int layer, MixingSSType type, int nPeriod, List<string> speciesList, List<List <double >> speciesValue)
        {

            this._row = row;

            this._col = col;

            this._layer = layer;

            this._ssType = type;



            this._spDic = new Dictionary<string, List<double>>();

            int j = 0;
            foreach (string sp in speciesList)
            {
                List<double> value = new List<double>();            
                for (int i = 0; i < nPeriod; i++)
                {
                    value.Add(speciesValue[j][i]);

                }

                this._spDic.Add(sp, value);
                j++;
            }


            this._nPeriods = nPeriod;






        }


        int _row;

        public int Row
        {
            get { return _row; }
            set { _row = value; }
        }


        int _col;

        public int Col
        {
            get { return _col; }
            set { _col = value; }
        }

        int _layer;

        public int Layer
        {
            get { return _layer; }
            set { _layer = value; }
        }



        int _nPeriods;

        public int NPeriods
        {
            get { return _nPeriods; }
            set { _nPeriods = value; }
        }



        MixingSSType _ssType;

        public MixingSSType SsType
        {
            get { return _ssType; }
            set { _ssType = value; }
        }


        Dictionary<string, List<double>> _spDic;

        public Dictionary<string, List<double>> SpDic
        {
            get { return _spDic; }
            set { _spDic = value; }
        }

      



        public void OnStressPeriodReset(int nPeriods)
        {

            foreach (KeyValuePair<string,List<double>> item in this._spDic)
            {
                item.Value.Clear();

                for (int i = 0; i < nPeriods; i++)
                {
                    item.Value.Add(0);
                    
                }
                
            }

            this._nPeriods = nPeriods;

            


        }


    

        public void OnSpeciesReset(List<string> spNames)
        {


            this._spDic.Clear();

            for (int i = 0; i < spNames.Count; i++)
            {

                List<double> lst = new List<double>();

                for (int j = 0; j < this._nPeriods; j++)
                {
                    lst.Add(0);
                    
                }


                this._spDic.Add(spNames[i],lst);
                
            }


          


        }





        public object Clone()
        {
            MixingItem mi = (MixingItem)this.MemberwiseClone();

            mi._spDic = new Dictionary<string, List<double>>();

            foreach (KeyValuePair<string,List<double>> item in this._spDic)
            {
                List<double> value = new List<double>();
                value.AddRange(item.Value);
                mi._spDic.Add(item.Key,value);
                
            }

            return mi;

            
        }
    }
}
